package com.zlx.xbhy.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zlx.xbhy.entity.Article;
import com.zlx.xbhy.entity.Meeting;
import com.zlx.xbhy.mapper.MeetingMapper;
import com.zlx.xbhy.service.MeetingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
 * @ClassName MeetingServiceImpl
 * @Description TODO
 * @Author Edward
 * @Date 2020/11/22 15:35
 */
@Service
@Transactional
public class MeetingServiceImpl extends BaseServiceImpl<Meeting, Long> implements MeetingService {
    @Autowired
    private MeetingMapper meetingMapper;

    @Override
    public PageInfo<Meeting> selectPage(String title, Integer status, Integer start, Integer pageSize) {
        PageHelper.startPage(start, pageSize);
        return new PageInfo<>(meetingMapper.selectPage(title, status));
    }

    @Override
    public void addMeeting(Meeting meeting, String ids) {
        meeting.setPublishDate(new Date());
        meeting.setMakeUser(ids);
        //设置状态
        if (meeting.getEndTime().getTime() < new Date().getTime()) {
            //会议结束
            meeting.setStatus(2L);
        } else if (meeting.getStartTime().getTime() > new Date().getTime()) {
            //会议未开始
            meeting.setStatus(0L);
        } else if (meeting.getStartTime().getTime() < new Date().getTime() && meeting.getEndTime().getTime() > new Date().getTime()) {
            //会议进行中
            meeting.setStatus(1L);
        }
        meetingMapper.insert(meeting);
    }

    @Override
    public List<Meeting> selectAlls() {
        return meetingMapper.selectAlls();
    }

    @Override
    public List<Meeting> countNew() {
        List<Meeting> list = new ArrayList<>();
        Collections.addAll(list, meetingMapper.countNew(0), meetingMapper.countNew(1),
                meetingMapper.countNew(2), meetingMapper.countNew(3), meetingMapper.countNew(4),
                meetingMapper.countNew(5), meetingMapper.countNew(6),meetingMapper.
                        countNew(7),meetingMapper.countNew(8));
        Collections.reverse(list);
        return list;
    }
}
